package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.log4j.Logger;

public class ReadTxt {
	
	private static final Logger LOG = Logger.getLogger(ReadTxt.class);

	private void excute() {
		File file = new File("I:/data/third.txt");
		BufferedReader br = null;
		String head = "A0101-";
		String arr = "";
		BufferedReader  reader = null;
		int i = 7;
		try {
			reader = new BufferedReader (new FileReader(file));
			br = new BufferedReader(reader);
			String line = null;
			StringBuilder stringBuilder = new StringBuilder("\"");
			while((line = br.readLine()) != null) {
				//.substring(7, br.readLine().length());
				if(line.substring(i-6, i).equals(head)) {
//					LOG.info("TRUE");
//					LOG.info(line.substring(0, 7));
//					LOG.info(head);
					stringBuilder.append(line.substring(i, line.length()));
				} else {
					stringBuilder.append(line.substring(i, line.length())+ "\",\n\"");
//					LOG.info("FLASE");
//					LOG.info(line.substring(0, 7));
//					LOG.info(head);
				}
				i = line.indexOf("-");
				head = line.substring(i-6, i);
			}
//			LOG.info(head);
			LOG.info(stringBuilder);
		} catch (FileNotFoundException e) {
			LOG.info(e);
		} catch (IOException e) {
				LOG.info(e);
		} finally {
			try {
//				br.close();
				reader.close();
			} catch (IOException e) {
				LOG.info(e);
			}
		}
	}
	
	/**
	 * @author suwy
	 * @date 2014-2-12
	 * @todo TODO BufferedReader 读取文件
	 */
	private static String loadPage(String name) {
        StringBuffer output = new StringBuffer();
        try {
            FileReader file = new FileReader(name);
            BufferedReader buff = new BufferedReader(file);
            boolean eof = false;
            while (!eof) {
                String line = buff.readLine();
                if (line == null)
                    eof = true;
                else
                    output.append(line + "\n");
            }
            buff.close();
        } catch (IOException e) {
            System.out.println("Error -- " + e.toString());
        }
        return output.toString();
    }
	
	public static void main(String[] args) {
		ReadTxt instance = new ReadTxt();
		instance.excute();
	}

}